mui.init();
mui.plusReady(function() {
	//接收数据
	var self = plus.webview.currentWebview();
	var data = self.data;
	var index = self.index;

	mui('.mui-scroll-wrapper').scroll();
	
	mui.previewImage(); // 图片单击预览

	//index:待评价->0
	//		已评价->1
	//		被评价->2			
	//顶部页面名称设置
	var indexTitle = "";
	switch(index) {
		case 0:
			indexTitle = "待评价"
			break;
		case 1:
			indexTitle = "已评价"
			break;
		case 2:
			indexTitle = "被评价"
			break;
		default:
			console.log("index溢出")
			break;
	}
	document.querySelector(".mui-title").innerHTML = indexTitle;

	(function($) {
		$.ready(function() {
			console.log(data);
			// 默认缩略头像设置
			var myCell = data.addname.split("");
			var myCellNode;
			if(isChinese(data.addname)) {
				myCellNode = myCell[myCell.length - 1];
			} else {
				myCellNode = myCell[0].toUpperCase();
			}
			console.log(myCellNode);

			// 详情图片集合
			var picSet = data.pics;
			var imgHTML = '';
			for (var i = 0; i < picSet.length; i++) {
				imgHTML += "<div class=\"slide-item\"><a><img class=\"my-sm-img\" data-preview-src=\"\" data-preview-group=\"1\" style=\"height: 100%; width: 100%;\" src=\"http://app.xiaoweicanting.com/" + picSet[i] + " \" alt=\"\"></a></div>"
			}
			imgHTML = "<div  class=\"slide-box\">" + imgHTML + "</div>";

			// 加急标志设置 faultlevel 3->加急 2->紧急
			var faultlevel = "";
			if(data.faultlevel == 3) {
				faultlevel = "urgency-level-1";
			} else if(data.faultlevel == 2) {
				faultlevel = "urgency-level-2";
			}

			var header_text = document.querySelector(".info-header");
			console.log(header_text); 

			header_text.innerHTML = "<div class=\"header-img\"><img src=\"http://app.xiaoweicanting.com/" + data.equipmentpic + " \" alt=\"\"></div><div class=\"header-text\"><div class=\"my-title\">"
				+ data.equipmentname + "</div><div class=\"my-subTitle\">编号: " + data.equipmentid + "</div><div class=\"my-subTitle\">工单等级: <div class=\" " + faultlevel + " \"></div></div></div>";

			var my_table01 = document.getElementById("my-table-view01");

			my_table01.innerHTML = "<li class=\"mui-table-view-cell\"><a><div class=\"my-cell-row\"><div class=\"my-cell-title\"><span class=\"circle-name\">"
				+ myCellNode + "</span> " + data.addname + "</div><div class=\"my-cell-name\">" + data.departmentname + " "
				+ data.addurole + "</div></div></a></li>	<li class=\"mui-table-view-cell\"><a><div class=\"my-cell-row\"><div class=\"my-cell-title\">提交时间</div><div>"
				+ data.addtime + "</div></div></a></li>	<li class=\"mui-table-view-cell\"><a><div class=\"my-cell-row\"><div class=\"my-cell-title\">故障原因</div><div>"
				+ data.title + "</div></div></a></li>    <li class=\"mui-table-view-cell\"><a><div class=\"my-cell-row\"><div class=\"my-cell-title\">维修厂家</div><div>"
				+ data.factoryname + "</div></div></a></li>    <li class=\"mui-table-view-cell\"><a><div class=\"my-cell-row\"><div class=\"my-cell-title\">维修人员</div><div>"
				+ data.workername + "</div></div></a></li>    <li class=\"mui-table-view-cell\"><a><div class=\"my-cell-cloumn\">    <div class=\"my-cell-title\">故障图片</div><div class=\"my-cell-img\">"
				+ imgHTML + "</div></div></a></li>"
				
			//生成星星评价html
			var starLi = "",
				starHtml = "",
				starLightNum = "";
			if(index !== 0) {
				switch (index){
					case 1: starLightNum = data.hospitalStar;
						break;
					case 2: starLightNum = data.workerStar; 
						break;
					default: console.log('index溢出')
						break;
				}
				for(var j = 0; j < 5; j++) {
					if(j < starLightNum) {
						starLi += "<li class=\"light\"></li> ";
					} else {
						starLi += "<li></li> ";
					}
				}
				starHtml = "<div class=\"starNum\" id=\"mystarNum\"><ul>" + starLi + "</ul></div>";						
			}
			//待评价页面显示评价单,已评价和被评价页面显示评价内容
			if(index === 0) {
				document.getElementById("my-table-view02").style.display = "block";
				document.querySelector(".btn-bottom").style.display = "block";
			} else {
				var my_table03 = document.getElementById("my-table-view03");
				my_table03.style.display = "block";
				my_table03.innerHTML = "<li class=\"mui-table-view-cell\"><a><div class=\"my-cell-row\"><div class=\"my-cell-title\">服务态度</div><div>"
				+ starHtml + "</div></div></a></li>"							
			} 

		})

	})(mui);
})

// 中文判断
function isChinese(text) {
	var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
	if(reg.test(text)) {
		return true;
	} else {
		return false;
	}
}
